import { Injectable } from '@angular/core';
import { Action, NgxsOnInit, State, StateContext } from '@ngxs/store';
import { IncreaseTestNumber } from './system.action';

export interface SystemStateModel {
  testNumber: number;
}

@State<SystemStateModel>({
  name: 'system',
  defaults: {
    testNumber: 0,
  },
})
@Injectable({
  providedIn: 'root',
})
export class SystemState implements NgxsOnInit {
  ngxsOnInit(ctx: StateContext<any>): void {
    ctx.patchState({});
  }

  @Action(IncreaseTestNumber)
  IncreaseTestNumber(ctx: StateContext<SystemStateModel>) {
    ctx.patchState({testNumber: ctx.getState().testNumber++});
  }

}
